// ----------------------------------------------------------------------
// Include files
// ----------------------------------------------------------------------
#include	<string.h>
#include	"video.h"

#if	defined(__USE_CMOS_PS1400K__)
// ----------------------------------------------------------------------
// Struct/Union Types and define
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Static Global Data section variables
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// External Variable 
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Static Prototype Functions
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Static functions
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Exported functions
// ----------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------

void PS1400K_Initialize(void)
{	
#if 1
	
	UARTprintf("PS1400K_Initialize_170323\n\r");

//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0340,0x05B0); // frame_length_lines
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0342,0x0B48); // line_length_pck
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0340,0x0672); // frame_length_lines
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0342,0x0BB8); // line_length_pck

//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0346,0x0030); // y_addr_start
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x034A,0x05CF); // y_addr_end
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x034E,0x05A0); // y_output_size
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0346,0x0008); // y_addr_start
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x034A,0x05F7); // y_addr_end
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x034E,0x05F0); // y_output_size	
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0202,0x0590); // int time 1/30sec
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0300,0x0003); // pixel clock divider
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0304,0x0006); // pre divider
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0306,0x005E); // pll multiplier
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0308,0x000C); // op clock divider
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0304,0x0007); // pre divider
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0306,0x0080); // pll multiplier
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0308,0x000C); // op clock divider

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3060,0x0000); // defect correction off
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x309E,0x800F); // output config
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30A4,0x0002); // lvds SOF port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30A6,0x0006); // lvds SOF port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30A8,0x0012); // lvds SOF port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30AA,0x0016); // lvds SOF port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30AC,0x0003); // lvds EOF port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30AE,0x0007); // lvds EOF port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B0,0x0013); // lvds EOF port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B2,0x0017); // lvds EOF port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B4,0x0000); // lvds SOL port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B6,0x0004); // lvds SOL port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B8,0x0010); // lvds SOL port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30BA,0x0014); // lvds SOL port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30BC,0x0001); // lvds EOL port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30BE,0x0005); // lvds EOL port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30C0,0x0011); // lvds EOL port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30C2,0x0015); // lvds EOL port 3

	
	
	
	//old
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3010,0x003F); // correction
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3012,0x1033); // correction
		
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D0,0x5700); // blacksun
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D2,0x0A04); // sig_clamp
	
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D4,0x8A20); // pixbuf/bsun bias
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D4,0xAA20); // pixbuf/bsun bias	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D4,0xCA20); // pixbuf/bsun bias (new)

//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x146A); // gref gload
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x148A); // gref gload
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x14AA); // gref gload	(new)

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D8,0x000F); // gref pload
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DA,0x0404); // adc_bias2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DA,0x0416); // adc_bias2	(new)
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DC,0x4463); // pns
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32E0,0x02CB);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32EE, 0x1002);  // sub-lvds reg enable	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32E6,0x0FA3);

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F0,0x0F00); // precb delay

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F2,0x90C0); // ud_rst
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F4,0x70B0); // ud_sig/ov_rst
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F6,0x23B0); // ov_sig, nosh	

//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F2,0x70C0); // ud_rst


	
/*	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3010,0x003F); // correction
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3012,0x1033); // correction
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D0,0x5700); // blacksun
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D2,0x0A04); // sig_clamp
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D4,0xCA20); // pixbuf/bsun bias
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x14AA); // gref gload
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D8,0x000F); // gref pload
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DA,0x0416); // adc_bias2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DC,0x4463); // pns
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32E0,0x02CB);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32E6,0x0FA3);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30EE,0x1002);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F0,0x0F00); // precb delay
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F2,0x70C0); // ud_rst
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F4,0x70B0); // ud_sig/ov_rst
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F6,0x23B0); // ov_sig, nosh
*/
	
	
	//Timing
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3210,0x8040);	// timing start
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3212,0x1130);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3214,0x8152);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3216,0x4280);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3218,0x00C0);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321A,0x835E);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321C,0x8055);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321E,0x5F82);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3220,0x4180);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3222,0x5680);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3224,0x5910);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3226,0x039C);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3228,0x1003);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322A,0x8341);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322C,0x8360);

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322E,0x9753);	//

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3230,0x8320);	////

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3232,0x18E3);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3234,0x5B83);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3236,0x5C8D);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3238,0x5392);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323A,0x6680);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323C,0x66A4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323E,0x509C);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3240,0x4383);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3242,0x0600);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3244,0x8845);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3246,0x9C06);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3248,0x208D);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324A,0x43CE);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324C,0x53FC);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324E,0x5392);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3250,0x6780);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3252,0x67A4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3254,0x1060);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3256,0xFFA8);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3258,0x1300);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325A,0x60FF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325C,0xDD00);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325E,0xC082);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3260,0x4280);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3262,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3264,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3266,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3268,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326A,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326C,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326E,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3270,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3272,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3274,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3276,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3278,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327A,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327C,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327E,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3280,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3282,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3284,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3286,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3288,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328A,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328C,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328E,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3290,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3292,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3294,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3296,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3298,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329A,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329C,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329E,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A0,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A2,0x4082);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A4,0x5956);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A6,0x20C0);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A8,0x8070);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AA,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AC,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AE,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B0,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0100,0x0001); // streaming

	/*
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3210,0x8040);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3212,0x1130);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3214,0x8152);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3216,0x4280);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3218,0x00C0);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321A,0x835E);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321C,0x8055);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321E,0x5F82);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3220,0x4180);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3222,0x5680);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3224,0x5910);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3226,0x039C);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3228,0x1003);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322A,0x8341);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322C,0x8360);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322E,0x8365);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3230,0x9253);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3232,0x8320);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3234,0x18C9);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3236,0x5B83);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3238,0x5C8D);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323A,0x5392);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323C,0x6680);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323E,0x66A4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3240,0x509C);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3242,0x4383);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3244,0x0600);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3246,0x8845);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3248,0x9C06);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324A,0x208D);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324C,0x43FF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324E,0xB253);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3250,0xE253);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3252,0x9267);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3254,0x8067);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3256,0xA410);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3258,0x60FF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325A,0xA813);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325C,0x0060);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325E,0xF900);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3260,0xC082);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3262,0x4280);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3264,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3266,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3268,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3270,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3272,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3274,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3276,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3278,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3280,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3282,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3284,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3286,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3288,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3290,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3292,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3294,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3296,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3298,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A0,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A2,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A4,0x4082);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A6,0x5956);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A8,0x20C0);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AA,0x8265);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AC,0x8670);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AE,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B0,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B2,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B4,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0100,0x0001); // streaming
	*/

#else
	UARTprintf("PS1400K_Initialize_170316\n\r");
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0340,0x05B0); // frame_length_lines
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0342,0x0B48); // line_length_pck
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0346,0x0030); // y_addr_start
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x034A,0x05CF); // y_addr_end
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x034E,0x05A0); // y_output_size
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0202,0x0590); // int time 1/30sec
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0300,0x0003); // pixel clock divider
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0304,0x0006); // pre divider
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0306,0x005E); // pll multiplier
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0308,0x000C); // op clock divider
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3060,0x0000); // defect correction off
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x309E,0x800F); // output config

	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30A4,0x0002); // lvds SOF port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30A6,0x0006); // lvds SOF port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30A8,0x0012); // lvds SOF port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30AA,0x0016); // lvds SOF port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30AC,0x0003); // lvds EOF port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30AE,0x0007); // lvds EOF port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B0,0x0013); // lvds EOF port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B2,0x0017); // lvds EOF port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B4,0x0000); // lvds SOL port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B6,0x0004); // lvds SOL port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30B8,0x0010); // lvds SOL port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30BA,0x0014); // lvds SOL port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30BC,0x0001); // lvds EOL port 0
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30BE,0x0005); // lvds EOL port 1
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30C0,0x0011); // lvds EOL port 2
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x30C2,0x0015); // lvds EOL port 3
	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3010,0x001F); // correction
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D0,0x5700); // blacksun
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D2,0x0A04); // sig_clamp
	
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D4,0x8A20); // pixbuf/bsun bias
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D4,0xAA20); // pixbuf/bsun bias

//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x146A); // gref gload
//	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x148A); // gref gload
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D6,0x14CC); // gref gload

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32D8,0x000F); // gref pload
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DA,0x0404); // adc_bias2

	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32DC,0x4463); // pns
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32E0,0x02CB);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32EE, 0x1002);  // sub-lvds reg enable	
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32E6,0x0FA3);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F0,0x0F00); // precb delay
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F2,0x90C0); // ud_rst
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F4,0x9090); // ud_sig/ov_rst
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32F6,0x2390); // ov_sig, nosh
	//Timing
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3210,0x8040);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3212,0x1130);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3214,0x8152);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3216,0x4280);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3218,0x00C0);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321A,0x835E);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321C,0x8055);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x321E,0x5F82);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3220,0x4180);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3222,0x5680);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3224,0x5910);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3226,0x039C);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3228,0x1003);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322A,0x8341);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322C,0x8360);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x322E,0x8365);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3230,0x9253);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3232,0x8320);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3234,0x18C9);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3236,0x5B83);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3238,0x5C8D);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323A,0x5392);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323C,0x6680);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x323E,0x66A4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3240,0x509C);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3242,0x4383);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3244,0x0600);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3246,0x8845);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3248,0x9C06);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324A,0x208D);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324C,0x43FF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x324E,0xB253);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3250,0xE253);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3252,0x9267);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3254,0x8067);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3256,0xA410);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3258,0x60FF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325A,0xA813);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325C,0x0060);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x325E,0xF900);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3260,0xC082);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3262,0x4280);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3264,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3266,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3268,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x326E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3270,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3272,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3274,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3276,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3278,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x327E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3280,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3282,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3284,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3286,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3288,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x328E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3290,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3292,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3294,0x4083);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3296,0x4088);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x3298,0x4181);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329A,0x4388);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329C,0x44B4);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x329E,0x4488);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A0,0x4381);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A2,0x4188);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A4,0x4082);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A6,0x5956);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32A8,0x20C0);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AA,0x8265);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AC,0x8670);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32AE,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B0,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B2,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x32B4,0xFFFF);
	CMOS_WordWrite(I2C_PS1400K_ADDR, 0x0100,0x0001); // streaming
#endif

}

#endif	
/*  FILE_END_HERE */
